﻿using System.Collections.Generic;
using System.Text;
using MySql.Data.MySqlClient;
using System;
using System.Windows.Forms;

namespace 水牛管理系统.UI {
    public partial class VisitorManage : Form {
        public VisitorManage() {
            InitializeComponent();
        }

        private void VisitorManage_Load(object sender, EventArgs e) {

        }

        private void findUser(object sender, EventArgs e) {
            String userCardId = textBox_cardId.Text.ToString();
            MySqlCommand cmd = new MySqlCommand("select * from user where user_card_id=@userCardId", new Utils.DatebaseUtil().open());
            cmd.Parameters.AddWithValue("userCardId", userCardId);
            MySqlDataReader reader = cmd.ExecuteReader();
            if (reader.HasRows) {
                reader.Read();
                label_name.Text = reader.GetString("user_name");
                label_balance.Text = reader.GetString("user_card_balance");
            }
            else {
            }
            reader.Close();
        }

        private void butto_OK_Click(object sender, EventArgs e) {
            {
                MySqlCommand cmd = new MySqlCommand("update user set user_card_balance=@a where user_card_id=@b", new Utils.DatebaseUtil().open());
                float newBalance = float.Parse(label_balance.Text) + float.Parse(textBox_balance.Text);
                cmd.Parameters.AddWithValue("a", newBalance);
                cmd.Parameters.AddWithValue("b", textBox_cardId.Text);
                if (cmd.ExecuteNonQuery() > 0) {
                    MessageBox.Show("充值成功！");

                }
            }
            {
                String userCardId = textBox_cardId.Text.ToString();
                MySqlCommand cmd = new MySqlCommand("select * from user where user_card_id=@userCardId", new Utils.DatebaseUtil().open());
                cmd.Parameters.AddWithValue("userCardId", userCardId);
                MySqlDataReader reader = cmd.ExecuteReader();
                if (reader.HasRows) {
                    reader.Read();
                    label_name.Text = reader.GetString("user_name");
                    label_balance.Text = reader.GetString("user_card_balance");
                }
                else {
                }
                reader.Close();
            }
        }
    }
}
